<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const goodsList = [
        {
          id: '4001172',
          name: '张三',
          price: 289.9,
          count: 2,
          spec: { color: '白色' },
        },
        {
          id: '4001009',
          name: '李四',
          price: 109.8,
          count: 3,
          spec: { size: '40cm*40cm', color: '黑色' },
        },
        {
          id: '4001874',
          name: '老六',
          price: 488,
          count: 1,
          spec: { color: '青色', sum: '一大四小' },
        },
        {
          id: '4001649',
          name: '老六',
          price: 139,
          count: 1,
          spec: { size: '小号', color: '紫色' },
          gift: '50g茶叶,清洗球,宝马, 奔驰',
        },
      ]

      // 封装函数 找到老六这个对象 返回整个对象出来
      const arr = goodsList.map((item) => {
        if (item.name === '老六') {
          console.log(item)
        }
      })

      // 封装函数 找到老六这俩项 筛选出来
      const arr1 = goodsList.filter((item) => item.name === '老六')
      console.log(arr1)

      // 封装函数 把所有的价格累加
      const arr2 = goodsList.reduce((item, index) => item + index.price, 0)
      console.log(arr2)
      // 数组对象解构出来
      let [{id, name,price,count,spec,spec:{size,color},gift}] = goodsList
      console.log(spec);
    </script>
  </body>
</html>
